home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
BBS-Archive
/
Comm
/
term-source.lha
/
Extras
/
Source
/
term-Source.lha
/
PhonePanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-01
|
53KB
|
2,331 lines
/*
** PhonePanel.c
**
** The phonebook and support routines
**
** Copyright © 1990-1995 by Olaf `Olsen' Barthel
** All Rights Reserved
*/
#include "termGlobal.h"
/* Gadget IDs. */
enum { GAD_NAMELIST, GAD_EDIT,
GAD_NAME, GAD_COMMENT, GAD_PHONENUMBER, GAD_QUICKMENU,
GAD_NEWENTRY, GAD_DIALLIST, GAD_LOADLIST, GAD_COPYCONFIG,
GAD_CLONEENTRY, GAD_CLEARLIST, GAD_SORTLIST, GAD_PASSWORD,
GAD_REMOVEENTRY, GAD_USEIT, GAD_SAVELIST, GAD_PRINT,
GAD_TAG, GAD_UNTAG, GAD_TAG_ALL, GAD_TOGGLE_ALL,
GAD_CANCEL
};
/* Editing IDs. */
enum { EDIT_SERIAL, EDIT_MODEM, EDIT_SCREEN, EDIT_TERMINAL,
EDIT_EMULATION, EDIT_CLIPBOARD, EDIT_CAPTURE, EDIT_COMMANDS,
EDIT_MISC, EDIT_PATHS, EDIT_TRANSFER, EDIT_TRANSLATION,
EDIT_KEYMACROS, EDIT_CURSORKEYS,
EDIT_FASTMACROS, EDIT_PASSWORD, EDIT_RATES };
/* What action is to follow clicking into the listview. */
enum { CLICK_NONE,CLICK_SELECT,CLICK_TOGGLE,CLICK_DIAL };
/* Some hints. */
STATIC LONG LastSelected,LastNumPhoneEntries;
/* ListViewRender():
*
* This callback routine is responsible for rendering
* the single listview entries.
*/
STATIC ULONG __saveds __asm
ListViewRender(register __a0 struct Hook *Hook,register __a1 struct LVDrawMsg *Msg,register __a2 struct PhoneNode *Node)
{
/* We only know how to redraw lines. */
if(Msg -> lvdm_MethodID == LV_DRAW)
{
struct RastPort *RPort = Msg -> lvdm_RastPort;
LONG Count = Node -> Entry -> Count + 1,
Left = Msg -> lvdm_Bounds . MinX,
Top = Msg -> lvdm_Bounds . MinY,
Width = Msg -> lvdm_Bounds . MaxX - Msg -> lvdm_Bounds . MinX + 1,
Height = Msg -> lvdm_Bounds . MaxY - Msg -> lvdm_Bounds . MinY + 1,
FgPen,BgPen,
Template,
Len,LabelLen;
UBYTE String[80],Num[8];
/* Determine the rendering pens. */
switch(Msg -> lvdm_State)
{
case LVR_SELECTEDDISABLED:
case LVR_NORMALDISABLED:
case LVR_NORMAL:
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[TEXTPEN];
BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[BACKGROUNDPEN];
break;
case LVR_SELECTED:
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLTEXTPEN];
BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLPEN];
break;
}
if(Count > 0)
{
if(Msg -> lvdm_DrawInfo -> dri_Pens[HIGHLIGHTTEXTPEN] != BgPen)
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[HIGHLIGHTTEXTPEN];
}
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + 1,Top + Height - 1);
Left += 2;
Width -= 2;
/* Determine maximum index text length. */
Template = 3 * ((ULONG)Hook -> h_Data) + TextLength(RPort," - ",3);
/* Get the vanilla name. */
strcpy(String,&Node -> VanillaNode . ln_Name[6]);
/* Set the rendering pens. */
SetDrMd(RPort,JAM2);
SetBPen(RPort,BgPen);
/* Has this entry been selected? */
if(Count > 0)
{
LONG Delta;
/* Set up the header. */
SPrintf(Num,"%3ld - ",Count);
/* Determine header length. */
Len = TextLength(RPort,Num,6);
/* Fill the space to precede the header. */
if((Delta = Template - Len) > 0)
{
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Delta - 1,Top + Height - 1);
}
/* Render the header, right-justified. */
SetAPen(RPort,FgPen);
Move(RPort,Left + Delta,Top + RPort -> Font -> tf_Baseline);
Text(RPort,Num,6);
}
else
{
/* Fill the blank space to precede the vanilla name. */
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Template - 1,Top + Height - 1);
SetAPen(RPort,FgPen);
}
/* Adjust width and area left edge. */
Left += Template;
Width -= Template;
/* Determine length of vanilla name. */
LabelLen = strlen(String);
/* Try to make it fit. */
while(LabelLen > 0 && (Len = TextLength(RPort,String,LabelLen)) > Width)
LabelLen--;
/* Print the vanilla name if possible. */
if(LabelLen)
{
Move(RPort,Left,Top + RPort -> Font -> tf_Baseline);
Text(RPort,String,LabelLen);
Left += Len;
Width -= Len;
}
/* Fill the area to follow the vanilla name. */
if(Width > 0)
{
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Width - 1,Top + Height - 1);
}
/* If the item happens to be disabled, draw the cross-hatch
* pattern across it.
*/
if(Msg -> lvdm_State == LVR_SELECTEDDISABLED || Msg -> lvdm_State == LVR_NORMALDISABLED)
{
SetDrMd(RPort,JAM1);
SetAPen(RPort,Msg -> lvdm_DrawInfo -> dri_Pens[BLOCKPEN]);
SetAfPt(RPort,(UWORD *)&Ghosting,1);
RectFill(RPort,Msg -> lvdm_Bounds . MinX,Msg -> lvdm_Bounds . MinY,Msg -> lvdm_Bounds . MaxX,Msg -> lvdm_Bounds . MaxY);
SetAfPt(RPort,NULL,0);
}
return(LVCB_OK);
}
else
return(LVCB_UNKNOWN);
}
STATIC ULONG __saveds __asm
EditViewRender(register __a0 struct Hook *Hook,register __a1 struct LVDrawMsg *Msg,register __a2 struct Node *Node)
{
/* We only know how to redraw lines. */
if(Msg -> lvdm_MethodID == LV_DRAW)
{
struct RastPort *RPort = Msg -> lvdm_RastPort;
LONG Left = Msg -> lvdm_Bounds . MinX,
Top = Msg -> lvdm_Bounds . MinY,
Width = Msg -> lvdm_Bounds . MaxX - Msg -> lvdm_Bounds . MinX + 1,
Height = Msg -> lvdm_Bounds . MaxY - Msg -> lvdm_Bounds . MinY + 1,
FgPen,BgPen,
Template,
Len,LabelLen;
STRPTR String = Node -> ln_Name;
/* Determine the rendering pens. */
switch(Msg -> lvdm_State)
{
case LVR_SELECTEDDISABLED:
case LVR_NORMALDISABLED:
case LVR_NORMAL:
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[TEXTPEN];
BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[BACKGROUNDPEN];
break;
case LVR_SELECTED:
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLTEXTPEN];
BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLPEN];
break;
}
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + 1,Top + Height - 1);
Left += 2;
Width -= 2;
/* Determine maximum index text length. */
Template = TextLength(RPort,"*",1);
/* Set the rendering pens. */
SetDrMd(RPort,JAM2);
SetBPen(RPort,BgPen);
/* Has this entry been selected? */
if(*String == '*')
{
/* Render the header, right-justified. */
SetAPen(RPort,FgPen);
Move(RPort,Left,Top + RPort -> Font -> tf_Baseline);
Text(RPort,"*",1);
}
else
{
/* Fill the blank space to precede the vanilla name. */
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Template - 1,Top + Height - 1);
SetAPen(RPort,FgPen);
}
/* Adjust width and area left edge. */
Left += Template;
Width -= Template;
String++;
/* Determine length of vanilla name. */
LabelLen = strlen(String);
/* Try to make it fit. */
while(LabelLen > 0 && (Len = TextLength(RPort,String,LabelLen)) > Width)
LabelLen--;
/* Print the vanilla name if possible. */
if(LabelLen)
{
Move(RPort,Left,Top + RPort -> Font -> tf_Baseline);
Text(RPort,String,LabelLen);
Left += Len;
Width -= Len;
}
/* Fill the area to follow the vanilla name. */
if(Width > 0)
{
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Width - 1,Top + Height - 1);
}
/* If the item happens to be disabled, draw the cross-hatch
* pattern across it.
*/
if(Msg -> lvdm_State == LVR_SELECTEDDISABLED || Msg -> lvdm_State == LVR_NORMALDISABLED)
{
SetDrMd(RPort,JAM1);
SetAPen(RPort,Msg -> lvdm_DrawInfo -> dri_Pens[BLOCKPEN]);
SetAfPt(RPort,(UWORD *)&Ghosting,1);
RectFill(RPort,Msg -> lvdm_Bounds . MinX,Msg -> lvdm_Bounds . MinY,Msg -> lvdm_Bounds . MaxX,Msg -> lvdm_Bounds . MaxY);
SetAfPt(RPort,NULL,0);
}
return(LVCB_OK);
}
else
return(LVCB_UNKNOWN);
}
STATIC VOID __regargs
UpdateEditList(struct Configuration *Config)
{
ULONG *Array;
WORD i;
Array = (ULONG *)Config;
for(i = 0 ; i < 10 ; i++)
{
if(Array[i])
EditLabels[i][0] = (UBYTE)'*';
else
EditLabels[i][0] = ' ';
}
if(Config -> TransferConfig)
EditLabels[10][0] = (UBYTE)'*';
else
EditLabels[10][0] = ' ';
EditLabels[15][0] = (UBYTE)'*';
EditLabels[16][0] = (UBYTE)'*';
if(Config -> FileConfig)
{
EditLabels[11][0] = (UBYTE)'*';
EditLabels[12][0] = (UBYTE)'*';
EditLabels[13][0] = (UBYTE)'*';
EditLabels[14][0] = (UBYTE)'*';
}
else
{
EditLabels[11][0] = ' ';
EditLabels[12][0] = ' ';
EditLabels[13][0] = ' ';
EditLabels[14][0] = ' ';
}
}
STATIC BOOLEAN
SaveChanges(struct Window *Parent)
{
return((BOOLEAN)MyEasyRequest(Parent,LocaleString(MSG_SAVE_CHANGES),LocaleString(MSG_GLOBAL_YES_NO_TXT)));
}
STATIC BYTE __regargs
EditConfig(struct Configuration *Config,UWORD Type,ULONG Qualifier,struct Window *Window)
{
STATIC LONG TypeMappings[15][2] =
{
EDIT_SERIAL, PREF_SERIAL,
EDIT_MODEM, PREF_MODEM,
EDIT_SCREEN, PREF_SCREEN,
EDIT_TERMINAL, PREF_TERMINAL,
EDIT_EMULATION, PREF_EMULATION,
EDIT_CLIPBOARD, PREF_CLIP,
EDIT_CAPTURE, PREF_CAPTURE,
EDIT_COMMANDS, PREF_COMMAND,
EDIT_MISC, PREF_MISC,
EDIT_PATHS, PREF_PATH,
EDIT_TRANSFER, PREF_TRANSFER,
EDIT_TRANSLATION, PREF_FILE,
EDIT_KEYMACROS, PREF_FILE,
EDIT_CURSORKEYS, PREF_FILE,
EDIT_FASTMACROS, PREF_FILE
};
struct FileRequester *FileRequest;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH],
*DummyChar;
BOOLEAN Changed = FALSE,
Default = FALSE,
FallBack = TRUE;
LONG PrefType;
WORD i;
APTR Data;
for(i = 0 ; i < 15 ; i++)
{
if(TypeMappings[i][0] == Type)
{
PrefType = TypeMappings[i][1];
break;
}
}
Data = GetConfigEntry(Config,PrefType);
if(CreateConfigEntry(Config,PrefType))
{
if(!Data)
ResetConfigEntry(Config,PrefType,FALSE);
switch(Type)
{
case EDIT_SERIAL:
Changed = SerialPanel(Config,&Default);
break;
case EDIT_MODEM:
Changed = ModemPanel(Config,&Default);
break;
case EDIT_SCREEN:
Changed = ScreenPanel(Config,&Default);
break;
case EDIT_TERMINAL:
Changed = TerminalPanel(Config,&Default);
break;
case EDIT_EMULATION:
Changed = EmulationPanel(Config,&Default);
break;
case EDIT_CLIPBOARD:
Changed = ClipPanel(Config,&Default);
break;
case EDIT_CAPTURE:
Changed = CapturePanel(Config,&Default);
break;
case EDIT_COMMANDS:
Changed = CommandPanel(Config,&Default);
break;
case EDIT_MISC:
Changed = MiscPanel(Config,&Default);
break;
case EDIT_PATHS:
Changed = PathPanel(Config,&Default);
break;
case EDIT_TRANSFER:
Changed = LibPanel(Config,&Default);
break;
case EDIT_TRANSLATION:
if(!(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)))
{
struct TranslationEntry **Send,**Receive = NULL;
BOOLEAN Success = FALSE;
strcpy(DummyBuffer,Config -> FileConfig -> TranslationFileName);
if(Send = AllocTranslationTable())
{
if(Receive = AllocTranslationTable())
{
Success = TRUE;
if(DummyBuffer[0])
{
if(!LoadTranslationTables(DummyBuffer,Send,Receive))
{
ShowError(Window,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
FillTranslationTable(Send);
FillTranslationTable(Receive);
}
}
else
{
FillTranslationTable(Send);
FillTranslationTable(Receive);
}
}
}
if(Success)
{
if(TranslationPanel(&Send,&Receive,DummyBuffer,Window))
{
if(Send || Receive)
{
if(IsStandardTable(Send) && IsStandardTable(Receive))
DummyBuffer[0] = 0;
if(DummyBuffer[0])
{
if(SaveChanges(Window))
{
if(!SaveTranslationTables(DummyBuffer,Send,Receive))
ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
}
}
}
else
DummyBuffer[0] = 0;
}
if(strcmp(Config -> FileConfig -> TranslationFileName,DummyBuffer))
{
strcpy(Config -> FileConfig -> TranslationFileName,DummyBuffer);
Changed = TRUE;
}
FallBack = FALSE;
}
if(Send)
FreeTranslationTable(Send);
if(Receive)
FreeTranslationTable(Receive);
}
if(FallBack)
{
SplitFileName(Config -> FileConfig -> TranslationFileName,&DummyChar,DummyBuffer);
if(FileRequest = GetFile(Window,LocaleString(MSG_PHONEPANEL_SELECT_TRANSLATION_TXT),DummyBuffer,DummyChar,DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
strcpy(Config -> FileConfig -> TranslationFileName,DummyBuffer);
FreeAslRequest(FileRequest);
Changed = TRUE;
}
}
break;
case EDIT_KEYMACROS:
if(!(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)))
{
struct MacroKeys *Keys;
if(Keys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY | MEMF_CLEAR))
{
strcpy(DummyBuffer,Config -> FileConfig -> MacroFileName);
if(DummyBuffer[0])
{
if(!LoadMacros(DummyBuffer,Keys))
ShowError(Window,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
}
if(MacroPanel(Keys,DummyBuffer,FALSE,Window))
{
if(SaveChanges(Window))
{
if(!WriteIFFData(DummyBuffer,Keys,sizeof(struct MacroKeys),ID_KEYS))
ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
}
}
if(strcmp(Config -> FileConfig -> MacroFileName,DummyBuffer))
{
strcpy(Config -> FileConfig -> MacroFileName,DummyBuffer);
Changed = TRUE;
}
FallBack = FALSE;
FreeVecPooled(Keys);
}
}
if(FallBack)
{
SplitFileName(Config -> FileConfig -> MacroFileName,&DummyChar,DummyBuffer);
if(FileRequest = GetFile(Window,LocaleString(MSG_PHONEPANEL_SELECT_KEYBOARD_MACROS_TXT),DummyBuffer,DummyChar,DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
strcpy(Config -> FileConfig -> MacroFileName,DummyBuffer);
FreeAslRequest(FileRequest);
Changed = TRUE;
}
}
break;
case EDIT_CURSORKEYS:
if(!(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)))
{
struct CursorKeys *Keys;
if(Keys = (struct CursorKeys *)AllocVecPooled(sizeof(struct CursorKeys),MEMF_ANY | MEMF_CLEAR))
{
strcpy(DummyBuffer,Config -> FileConfig -> CursorFileName);
if(DummyBuffer[0])
{
if(!ReadIFFData(DummyBuffer,Keys,sizeof(struct CursorKeys),ID_KEYS))
{
ResetCursorKeys(Keys);
ShowError(Window,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
}
}
else
ResetCursorKeys(Keys);
if(CursorPanel(Keys,DummyBuffer,Window))
{
if(SaveChanges(Window))
{
if(!WriteIFFData(DummyBuffer,Keys,sizeof(struct CursorKeys),ID_KEYS))
ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
}
}
if(strcmp(Config -> FileConfig -> CursorFileName,DummyBuffer))
{
strcpy(Config -> FileConfig -> CursorFileName,DummyBuffer);
Changed = TRUE;
}
FallBack = FALSE;
FreeVecPooled(Keys);
}
}
if(FallBack)
{
SplitFileName(Config -> FileConfig -> CursorFileName,&DummyChar,DummyBuffer);
if(FileRequest = GetFile(Window,LocaleString(MSG_PHONEPANEL_SELECT_CURSOR_KEYS_TXT),DummyBuffer,DummyChar,DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
strcpy(Config -> FileConfig -> CursorFileName,DummyBuffer);
FreeAslRequest(FileRequest);
Changed = TRUE;
}
}
break;
case EDIT_FASTMACROS:
if(!(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)))
{
struct List *List;
if(List = CreateList())
{
strcpy(DummyBuffer,Config -> FileConfig -> FastMacroFileName);
if(DummyBuffer[0])
{
if(!LoadFastMacros(DummyBuffer,List))
ShowError(Window,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
}
if(FastMacroPanel(List,DummyBuffer,Window,NULL))
{
if(SaveChanges(Window))
{
if(!SaveFastMacros(DummyBuffer,List))
ShowError(Window,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
}
}
if(strcmp(Config -> FileConfig -> FastMacroFileName,DummyBuffer))
{
strcpy(Config -> FileConfig -> FastMacroFileName,DummyBuffer);
Changed = TRUE;
}
FallBack = FALSE;
DeleteList(List);
}
}
if(FallBack)
{
SplitFileName(Config -> FileConfig -> FastMacroFileName,&DummyChar,DummyBuffer);
if(FileRequest = GetFile(Window,LocaleString(MSG_PHONEPANEL_SELECT_FAST_MACROS_TXT),DummyBuffer,DummyChar,DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
strcpy(Config -> FileConfig -> FastMacroFileName,DummyBuffer);
FreeAslRequest(FileRequest);
Changed = TRUE;
}
}
break;
}
if((!Changed && !Data) || Default)
{
DeleteConfigEntry(Config,PrefType);
if(Default)
Changed = TRUE;
}
}
else
DisplayBeep(Window -> WScreen);
return(Changed);
}
STATIC VOID __regargs
SetPanelState(struct LayoutHandle *Handle,struct List *PhoneList,LONG Count,LONG Selected)
{
if(NumPhoneEntries)
{
LT_SetAttributes(Handle,GAD_SAVELIST,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PRINT,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_SORTLIST,
GA_Disabled, NumPhoneEntries < 2,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PASSWORD,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_CLONEENTRY,
GA_Disabled, Selected == -1,
TAG_DONE);
LT_SetAttributes(Handle,GAD_REMOVEENTRY,
GA_Disabled, Selected == -1,
TAG_DONE);
LT_SetAttributes(Handle,GAD_COPYCONFIG,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_USEIT,
GA_Disabled, Selected == -1,
TAG_DONE);
if(Selected == -1)
{
LT_SetAttributes(Handle,GAD_EDIT,
GA_Disabled, TRUE,
TAG_DONE);
if(Selected != LastSelected)
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GA_Disabled, FALSE,
GTLV_Selected, ~0,
TAG_DONE);
LT_SetAttributes(Handle,GAD_NAME,
GTST_String, "",
GA_Disabled, TRUE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_COMMENT,
GTST_String, "",
GA_Disabled, TRUE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PHONENUMBER,
GTST_String, "",
GA_Disabled, TRUE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_QUICKMENU,
GTCB_Checked, FALSE,
GA_Disabled, TRUE,
TAG_DONE);
}
LT_SetAttributes(Handle,GAD_TAG,
GA_Disabled, TRUE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_UNTAG,
GA_Disabled, TRUE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_DIALLIST,
GA_Disabled, (Online && !Config -> MiscConfig -> ProtectiveMode) || !Count,
TAG_DONE);
}
else
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GA_Disabled, FALSE,
GTLV_Labels, PhoneList,
TAG_DONE);
if(Selected != LastSelected)
{
LT_SetAttributes(Handle,GAD_NAME,
GTST_String, Phonebook[Selected] -> Header -> Name,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_COMMENT,
GTST_String, Phonebook[Selected] -> Header -> Comment,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PHONENUMBER,
GTST_String, Phonebook[Selected] -> Header -> Number,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_QUICKMENU,
GTCB_Checked, Phonebook[Selected] -> Header -> QuickMenu,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, ~0,
TAG_DONE);
UpdateEditList(Phonebook[Selected] -> Config);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, EditList,
GA_Disabled, FALSE,
TAG_DONE);
}
else
{
LT_SetAttributes(Handle,GAD_EDIT,
GA_Disabled, FALSE,
TAG_DONE);
}
LT_SetAttributes(Handle,GAD_TAG,
GA_Disabled, Phonebook[Selected] -> Count != -1,
TAG_DONE);
LT_SetAttributes(Handle,GAD_UNTAG,
GA_Disabled, Phonebook[Selected] -> Count == -1,
TAG_DONE);
LT_SetAttributes(Handle,GAD_DIALLIST,
GA_Disabled, (Online && !Config -> MiscConfig -> ProtectiveMode) || !Phonebook[Selected] -> Header -> Number[0],
TAG_DONE);
}
LT_SetAttributes(Handle,GAD_TAG_ALL,
GA_Disabled, Count == NumPhoneEntries,
TAG_DONE);
LT_SetAttributes(Handle,GAD_TOGGLE_ALL,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_CLEARLIST,
GA_Disabled, !Count,
TAG_DONE);
}
else
{
LONG i;
for(i = GAD_NAMELIST ; i < GAD_CANCEL ; i++)
{
LT_SetAttributes(Handle,i,
GA_Disabled, i != GAD_LOADLIST && i != GAD_NEWENTRY,
TAG_DONE);
}
}
LastSelected = Selected;
}
BYTE
PhonePanel()
{
struct LayoutHandle *Handle;
struct PhoneNode *TempNode;
struct List *PhoneList;
LONG Count;
BYTE DialTheList = FALSE;
LastSelected = LastNumPhoneEntries = -17;
if(Phonebook && NumPhoneEntries)
{
LONG i;
if(!(PhoneList = CreatePhoneList()))
{
DisplayBeep(Window -> WScreen);
return(FALSE);
}
FreeDialList(TRUE);
for(i = 0, Count = -1 ; i < NumPhoneEntries ; i++)
{
if(Phonebook[i] -> Count > Count)
Count = Phonebook[i] -> Count;
}
Count++;
}
else
{
PhoneList = NULL;
Count = 0;
}
if(Handle = LT_CreateHandleTags(Window -> WScreen,
LH_LocaleHook, &LocaleHook,
/* LH_AutoActivate, TRUE,*/
TAG_DONE))
{
STATIC struct Hook ListViewHook =
{
{NULL},
(HOOKFUNC)ListViewRender
};
STATIC struct Hook EditViewHook =
{
{NULL},
(HOOKFUNC)EditViewRender
};
STATIC LONG LabelIDTable[] =
{
MSG_PHONEPANEL_LOAD_LIST_GAD,
MSG_PHONEPANEL_SAVE_LIST_GAD,
MSG_PHONEPANEL_PRINT_GAD,
MSG_PHONEPANEL_SORT_LIST_GAD,
MSG_PHONEPANEL_SET_PASSWORT_GAD,
MSG_PHONEPANEL_NEW_ENTRY_GAD,
MSG_PHONEPANEL_CLONE_ENTRY_GAD,
MSG_PHONEPANEL_REMOVE_ENTRY_GAD,
MSG_PHONEPANEL_COPY_CONFIG_GAD,
MSG_PHONEPANEL_USE_ENTRY_GAD,
MSG_PHONEPANEL_TAG_GAD,
MSG_PHONEPANEL_UNTAG_GAD,
MSG_PHONEPANEL_TAG_ALL_GAD,
MSG_PHONEPANEL_TOGGLE_ALL_GAD,
MSG_PHONEPANEL_UNTAG_ALL_GAD
};
struct IBox Bounds;
struct Window *PhoneWindow;
LONG i,Max,Size,MaxPen,MaxChars;
UBYTE SmallString[2];
for(i = MaxChars = 0 ; i < NumElements(LabelIDTable) ; i++)
{
if((Max = LT_LabelChars(Handle,LocaleString(LabelIDTable[i]))) > MaxChars)
MaxChars = Max;
}
MaxPen = MAX(Handle -> DrawInfo -> dri_Pens[BLOCKPEN],MAX(Handle -> DrawInfo -> dri_Pens[TEXTPEN],MAX(Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN],MAX(Handle -> DrawInfo -> dri_Pens[FILLTEXTPEN],MAX(Handle -> DrawInfo -> dri_Pens[FILLPEN],Handle -> DrawInfo -> dri_Pens[HIGHLIGHTTEXTPEN])))));
SmallString[1] = 0;
Max = 0;
for(i = MSG_PHONEPANEL_SERIAL_TXT ; i <= MSG_PHONEPANEL_RATES_TXT ; i++)
EditLabels[i - MSG_PHONEPANEL_SERIAL_TXT][0] = ' ';
for(i = '0' ; i <= '9' ; i++)
{
SmallString[0] = i;
if((Size = LT_LabelWidth(Handle,SmallString)) > Max)
Max = Size;
}
ListViewHook . h_Data = (APTR)Max;
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
/* LA_LabelID, MSG_V36_0132,*/
TAG_DONE);
{
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, LISTVIEW_KIND,
LA_LabelID, MSG_GLOBAL_NAME_LIST_GAD,
LA_ID, GAD_NAMELIST,
LA_Chars, 40,
LA_Lines, 4,
GTLV_CallBack, &ListViewHook,
GTLV_MaxPen, MaxPen,
LALV_CursorKey, TRUE,
LALV_MaxGrowX, 50,
LALV_MaxGrowY, 20,
LALV_ResizeX, TRUE,
LALV_ResizeY, TRUE,
Kick30 ? LALV_Link : TAG_IGNORE, NIL_LINK,
Kick30 ? TAG_IGNORE : LALV_TextAttr, ~0,
PhoneList ? GTLV_Labels : TAG_IGNORE, PhoneList,
TAG_DONE);
LT_New(Handle,
LA_Type, LISTVIEW_KIND,
LA_LabelID, MSG_PHONEPANEL_SETTINGS_TXT,
LA_Lines, 4,
LA_ID, GAD_EDIT,
LA_NoKey, TRUE,
GA_Disabled, TRUE,
GTLV_Labels, EditList,
GTLV_CallBack, &EditViewHook,
Kick30 ? TAG_IGNORE : LALV_TextAttr, ~0,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_PHONEPANEL_BBS_NAME_GAD,
LA_ID, GAD_NAME,
GTST_MaxChars, 39,
LA_Chars, 40,
GA_Disabled, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_PHONEPANEL_COMMENT_GAD,
LA_ID, GAD_COMMENT,
GTST_MaxChars, 99,
GA_Disabled, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_PHONEPANEL_PHONE_NUMBER_GAD,
LA_ID, GAD_PHONENUMBER,
GTST_MaxChars, 99,
LAST_LastGadget, TRUE,
GA_Disabled, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CHECKBOX_KIND,
LA_LabelID, MSG_PHONEPANEL_QUICK_MENU_GAD,
LA_ID, GAD_QUICKMENU,
GA_Disabled, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
LAXB_FullSize, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_NEW_ENTRY_GAD,
LA_ID, GAD_NEWENTRY,
LA_Chars, MaxChars,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_CLONE_ENTRY_GAD,
LA_ID, GAD_CLONEENTRY,
GA_Disabled, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_REMOVE_ENTRY_GAD,
LA_ID, GAD_REMOVEENTRY,
GA_Disabled, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_COPY_CONFIG_GAD,
LA_ID, GAD_COPYCONFIG,
GA_Disabled, !NumPhoneEntries,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_USE_ENTRY_GAD,
LA_ID, GAD_USEIT,
GA_Disabled, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_TAG_GAD,
LA_Chars, MaxChars,
LA_ID, GAD_TAG,
GA_Disabled, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_UNTAG_GAD,
LA_ID, GAD_UNTAG,
GA_Disabled, !Count,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_TAG_ALL_GAD,
LA_ID, GAD_TAG_ALL,
GA_Disabled, !NumPhoneEntries,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_TOGGLE_ALL_GAD,
LA_ID, GAD_TOGGLE_ALL,
GA_Disabled, !NumPhoneEntries,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_UNTAG_ALL_GAD,
LA_ID, GAD_CLEARLIST,
GA_Disabled, !Count,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_LOAD_LIST_GAD,
LA_ID, GAD_LOADLIST,
LA_Chars, MaxChars,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_SAVE_LIST_GAD,
LA_ID, GAD_SAVELIST,
GA_Disabled, !NumPhoneEntries,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_PRINT_GAD,
LA_ID, GAD_PRINT,
GA_Disabled, !NumPhoneEntries,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_SORT_LIST_GAD,
LA_ID, GAD_SORTLIST,
GA_Disabled, NumPhoneEntries < 2,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_SET_PASSWORT_GAD,
LA_ID, GAD_PASSWORD,
GA_Disabled, !NumPhoneEntries,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
LAXB_FullSize, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_PHONEPANEL_DIAL_LIST_GAD,
LA_ID, GAD_DIALLIST,
LABT_ReturnKey, TRUE,
LABT_ExtraFat, TRUE,
GA_Disabled, !Count || (Online && !Config -> MiscConfig -> ProtectiveMode),
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
Bounds . Left = WindowLeft + Window -> LeftEdge;
Bounds . Top = WindowTop + Window -> TopEdge;
Bounds . Width = WindowWidth;
Bounds . Height = WindowHeight;
if(PhoneWindow = LT_Layout(Handle,LocaleString(MSG_PHONEPANEL_PHONEBOOK_TXT),&Bounds,0,0,IDCMP_CLOSEWINDOW,0,
LAWN_HelpHook, &GuideHook,
// LAWN_Parent, Window,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_DragBar, TRUE,
WA_RMBTrap, TRUE,
WA_Activate, TRUE,
TAG_DONE))
{
struct IntuiMessage *Message;
BOOLEAN Done = FALSE;
ULONG MsgClass,
MsgQualifier,
CompleteQualifier;
UWORD MsgCode;
struct Gadget *MsgGadget;
BYTE ClickAction;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH],
*DummyChar;
LONG Selected = ~0,i,
MsgGadgetID;
struct FileRequester *FileRequest;
WORD Vanilla;
GuideContext(CONTEXT_PHONEBOOK);
PushWindow(PhoneWindow);
SetPanelState(Handle,PhoneList,Count,Selected);
do
{
if(Wait(PORTMASK(PhoneWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
{
FreeDialList(TRUE);
break;
}
while(Message = (struct IntuiMessage *)GT_GetIMsg(PhoneWindow -> UserPort))
{
MsgClass = Message -> Class;
MsgQualifier = Message -> Qualifier;
MsgCode = Message -> Code;
MsgGadget = (struct Gadget *)Message -> IAddress;
GT_ReplyIMsg(Message);
CompleteQualifier = MsgQualifier;
if(MsgClass == IDCMP_RAWKEY && (MsgCode == CURSORUP || MsgCode == CURSORDOWN))
MsgQualifier &= ~(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT);
LT_HandleInput(Handle,CompleteQualifier,&MsgClass,&MsgCode,&MsgGadget);
if(MsgClass == IDCMP_GADGETUP || MsgClass == IDCMP_IDCMPUPDATE)
MsgGadgetID = MsgGadget -> GadgetID;
else
MsgGadgetID = -1;
Vanilla = LT_GetCode(CompleteQualifier,MsgClass,MsgCode,MsgGadget);
switch(Vanilla)
{
case ' ':
if(Selected != -1)
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
if(Phonebook[Selected] -> Count == -1)
{
Phonebook[Selected] -> Count = Count++;
SPrintf(Phonebook[Selected] -> Node -> LocalName,"%3ld - %s",Count,Phonebook[Selected] -> Header -> Name);
LT_PressButton(Handle,GAD_TAG);
}
else
{
RemoveDialEntry(Selected);
Count--;
LT_PressButton(Handle,GAD_UNTAG);
}
SetPanelState(Handle,PhoneList,Count,Selected);
}
break;
case 127:
if(CompleteQualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
{
if(Count > 0)
{
MsgClass = IDCMP_GADGETUP;
MsgGadgetID = GAD_CLEARLIST;
}
}
else
{
if(Selected != -1 && Phonebook[Selected] -> Count != -1)
{
MsgClass = IDCMP_GADGETUP;
MsgGadgetID = GAD_UNTAG;
}
}
break;
}
if(MsgClass == IDCMP_CLOSEWINDOW)
{
FreeDialList(TRUE);
Done = TRUE;
}
if(MsgClass == IDCMP_GADGETUP)
{
switch(MsgGadgetID)
{
case GAD_TOGGLE_ALL:
{
LONG LocalCount = 0;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
for(i = 0 ; i < NumPhoneEntries ; i++)
{
if(Phonebook[i] -> Count == -1)
{
Phonebook[i] -> Count = LocalCount++;
SPrintf(Phonebook[i] -> Node -> LocalName,"%3ld - %s",LocalCount,Phonebook[i] -> Header -> Name);
}
else
RemoveDialEntry(i);
}
Count = LocalCount;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
break;
}
case GAD_TAG_ALL:
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
for(i = 0 ; i < NumPhoneEntries ; i++)
{
if(Phonebook[i] -> Count == -1)
{
Phonebook[i] -> Count = Count++;
SPrintf(Phonebook[i] -> Node -> LocalName,"%3ld - %s",Count,Phonebook[i] -> Header -> Name);
}
}
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
break;
case GAD_TAG:
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
Phonebook[Selected] -> Count = Count++;
SPrintf(Phonebook[Selected] -> Node -> LocalName,"%3ld - %s",Count,Phonebook[Selected] -> Header -> Name);
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
break;
case GAD_UNTAG:
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
RemoveDialEntry(Selected);
Count--;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
break;
case GAD_NAMELIST:
Selected = MsgCode;
if(Phonebook[Selected] -> Header -> Number[0] && Phonebook[Selected] -> Header -> Name[0])
{
if(MsgQualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
ClickAction = CLICK_TOGGLE;
else
ClickAction = CLICK_SELECT;
}
else
ClickAction = CLICK_SELECT;
if(ClickAction == CLICK_TOGGLE)
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
if(Phonebook[Selected] -> Count == -1)
{
Phonebook[Selected] -> Count = Count++;
SPrintf(Phonebook[Selected] -> Node -> LocalName,"%3ld - %s",Count,Phonebook[Selected] -> Header -> Name);
}
else
{
RemoveDialEntry(Selected);
Count--;
}
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
}
SetPanelState(Handle,PhoneList,Count,Selected);
break;
case GAD_CLEARLIST:
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
Count = 0;
for(i = 0 ; i < NumPhoneEntries ; i++)
{
SPrintf(Phonebook[i] -> Node -> LocalName," %s",Phonebook[i] -> Header -> Name);
Phonebook[i] -> Count = -1;
}
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
break;
case GAD_PRINT:
LT_LockWindow(PhoneWindow);
PrintPanel(PhoneWindow,PhoneList,Count);
LT_UnlockWindow(PhoneWindow);
LT_ShowWindow(Handle,TRUE);
break;
case GAD_USEIT:
if(Selected != ~0)
{
SaveConfig(Config,PrivateConfig);
SaveConfig(Phonebook[Selected] -> Config,Config);
strcpy(Password,Phonebook[Selected] -> Header -> Password);
strcpy(UserName,Phonebook[Selected] -> Header -> UserName);
ConfigSetup();
Done = TRUE;
ConfigChanged = FALSE;
}
break;
case GAD_NEWENTRY:
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
if(PhoneList)
{
DeletePhoneList(PhoneList);
PhoneList = NULL;
}
if(NewPhoneEntry())
{
if(PhoneList = CreatePhoneList())
{
Selected = NumPhoneEntries - 1;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GTLV_Selected, Selected,
GTLV_Top, Selected,
GTLV_MakeVisible, Selected,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
LT_Activate(Handle,GAD_NAME);
RebuildMenu = PhonebookChanged = TRUE;
}
else
goto ClearList;
}
else
goto ClearList;
break;
case GAD_CLONEENTRY:
if(Selected != ~0)
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
if(PhoneList)
{
DeletePhoneList(PhoneList);
PhoneList = NULL;
}
if(NewPhoneEntry())
{
if(PhoneList = CreatePhoneList())
{
LONG Tmp = Selected,i;
Selected = NumPhoneEntries - 1;
CopyMem(Phonebook[Tmp] -> Header,Phonebook[Selected] -> Header,sizeof(struct PhoneHeader));
Phonebook[Selected] -> Header -> QuickMenu = FALSE;
SPrintf(Phonebook[Selected] -> Node -> LocalName," %s",Phonebook[Selected] -> Header -> Name);
FreeTimeDateList((struct List *)&Phonebook[Selected] -> TimeDateList);
CopyTimeDateList((struct List *)&Phonebook[Tmp] -> TimeDateList,(struct List *)&Phonebook[Selected] -> TimeDateList,FALSE);
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GTLV_Selected, Selected,
GTLV_Top, Selected,
GTLV_MakeVisible, Selected,
TAG_DONE);
SetPanelState(Handle,PhoneList,Count,Selected);
/* Allocate space for the config data. */
for(i = PREF_SERIAL ; i <= PREF_TRANSFER ; i++)
{
if(GetConfigEntry(Phonebook[Tmp] -> Config,i))
CreateConfigEntry(Phonebook[Selected] -> Config,i);
}
/* Copy the data. */
SaveConfig(Phonebook[Tmp] -> Config,Phonebook[Selected] -> Config);
RebuildMenu = PhonebookChanged = TRUE;
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, ~0,
TAG_DONE);
UpdateEditList(Phonebook[Selected] -> Config);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, EditList,
TAG_DONE);
}
else
goto ClearList;
}
else
goto ClearList;
}
break;
case GAD_REMOVEENTRY:
if(Selected != ~0)
{
if(Phonebook[Selected] == ChosenEntry)
MyEasyRequest(PhoneWindow,LocaleString(MSG_PHONEPANEL_PHONE_ENTRY_IN_USE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
else
{
RebuildMenu = PhonebookChanged = TRUE;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels,~0,
TAG_DONE);
if(PhoneList)
{
DeletePhoneList(PhoneList);
PhoneList = NULL;
}
if(Phonebook[Selected] -> Count != -1)
{
RemoveDialEntry(Selected);
Count--;
}
RemPhoneEntry(Selected);
if(NumPhoneEntries > 0)
{
if(PhoneList = CreatePhoneList())
{
if(Selected == NumPhoneEntries)
Selected--;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GTLV_Selected, Selected,
TAG_DONE);
LT_SetAttributes(Handle,GAD_NAME,
GTST_String, Phonebook[Selected] -> Header -> Name,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_COMMENT,
GTST_String, Phonebook[Selected] -> Header -> Comment,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PHONENUMBER,
GTST_String, Phonebook[Selected] -> Header -> Number,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_QUICKMENU,
GTCB_Checked, Phonebook[Selected] -> Header -> QuickMenu,
GA_Disabled, FALSE,
TAG_DONE);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, ~0,
TAG_DONE);
UpdateEditList(Phonebook[Selected] -> Config);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, EditList,
GA_Disabled, FALSE,
TAG_DONE);
}
else
goto ClearList;
SetPanelState(Handle,PhoneList,Count,Selected);
}
else
{
ClearList: LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, &EmptyList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
Count = 0;
SetPanelState(Handle,PhoneList,Count,Selected);
}
}
}
break;
case GAD_NAME:
if(Selected != ~0)
{
strcpy(Phonebook[Selected] -> Header -> Name,(STRPTR)LT_GetAttributes(Handle,GAD_NAME,TAG_DONE));
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels,~0,
TAG_DONE);
if(PhoneList)
DeletePhoneList(PhoneList);
if(PhoneList = CreatePhoneList())
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GTLV_Selected, Selected,
GTLV_Top, Selected,
GTLV_MakeVisible, Selected,
TAG_DONE);
}
if(!Phonebook[Selected] -> Header -> Name[0])
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
if(Phonebook[Selected] -> Count != -1)
{
RemoveDialEntry(Selected);
Count--;
}
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GTLV_Selected, Selected,
GTLV_Top, Selected,
GTLV_MakeVisible, Selected,
TAG_DONE);
}
SetPanelState(Handle,PhoneList,Count,Selected);
RebuildMenu = PhonebookChanged = TRUE;
if(MsgCode == '\r')
LT_Activate(Handle,GAD_COMMENT);
}
break;
case GAD_COMMENT:
if(Selected != ~0)
{
strcpy(Phonebook[Selected] -> Header -> Comment,(STRPTR)LT_GetAttributes(Handle,GAD_COMMENT,TAG_DONE));
PhonebookChanged = TRUE;
if(MsgCode == '\r')
LT_Activate(Handle,GAD_PHONENUMBER);
}
break;
case GAD_QUICKMENU:
if(Selected != ~0)
{
if(Phonebook[Selected] -> Header -> QuickMenu != MsgCode)
{
Phonebook[Selected] -> Header -> QuickMenu = MsgCode;
RebuildMenu = PhonebookChanged = TRUE;
}
}
break;
case GAD_PHONENUMBER:
if(Selected != ~0)
{
strcpy(Phonebook[Selected] -> Header -> Number,(STRPTR)LT_GetAttributes(Handle,GAD_PHONENUMBER,TAG_DONE));
PhonebookChanged = TRUE;
if(!Phonebook[Selected] -> Header -> Number[0])
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
if(Phonebook[Selected] -> Count != -1)
{
RemoveDialEntry(Selected);
Count--;
}
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
}
SetPanelState(Handle,PhoneList,Count,Selected);
}
break;
case GAD_LOADLIST:
LT_LockWindow(PhoneWindow);
if(ChosenEntry)
MyEasyRequest(PhoneWindow,LocaleString(MSG_PHONEPANEL_PHONE_ENTRY_IN_USE_LOAD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
else
{
SplitFileName(LastPhone,&DummyChar,DummyBuffer);
if(FileRequest = GetFile(PhoneWindow,LocaleString(MSG_PHONEPANEL_LOAD_PHONEBOOK_TXT),DummyBuffer,DummyChar,DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
GTLV_Selected, ~0,
TAG_DONE);
if(PhoneList)
DeletePhoneList(PhoneList);
if(!LoadPhonebook(DummyBuffer))
ShowError(PhoneWindow,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
else
{
strcpy(LastPhone,DummyBuffer);
PhonebookChanged = FALSE;
RebuildMenu = TRUE;
}
if(PhoneList = CreatePhoneList())
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GA_Disabled, FALSE,
TAG_DONE);
FreeDialList(TRUE);
}
else
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, &EmptyList,
GA_Disabled, TRUE,
TAG_DONE);
}
Selected = ~0;
Count = 0;
SetPanelState(Handle,PhoneList,Count,Selected);
FreeAslRequest(FileRequest);
}
}
LT_UnlockWindow(PhoneWindow);
break;
case GAD_SORTLIST:
if(NumPhoneEntries > 1)
{
RebuildMenu = PhonebookChanged = TRUE;
LT_LockWindow(PhoneWindow);
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
SetPanelState(Handle,PhoneList,Count,Selected);
if(PhoneList)
DeletePhoneList(PhoneList);
SortPhoneEntries();
if(PhoneList = CreatePhoneList())
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
GTLV_Selected, ~0,
TAG_DONE);
}
else
Count = 0;
LT_UnlockWindow(PhoneWindow);
}
break;
case GAD_SAVELIST:
if(NumPhoneEntries)
{
SplitFileName(LastPhone,&DummyChar,DummyBuffer);
LT_LockWindow(PhoneWindow);
if(FileRequest = GetFile(PhoneWindow,LocaleString(MSG_PHONEPANEL_SAVE_PHONEBOOK_TXT),DummyBuffer,DummyChar,DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
{
if(!SavePhonebook(DummyBuffer))
ShowError(PhoneWindow,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
else
{
strcpy(LastPhone,DummyBuffer);
PhonebookChanged = FALSE;
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PhoneWindow);
}
break;
case GAD_COPYCONFIG:
LT_LockWindow(PhoneWindow);
if(Selected == ~0)
PhonebookChanged |= CopyPanel(NULL,Count > 0);
else
{
PhonebookChanged |= CopyPanel(Phonebook[Selected] -> Config,Count > 0);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, ~0,
TAG_DONE);
UpdateEditList(Phonebook[Selected] -> Config);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, EditList,
TAG_DONE);
}
LT_UnlockWindow(PhoneWindow);
LT_ShowWindow(Handle,TRUE);
break;
case GAD_PASSWORD:
LT_LockWindow(PhoneWindow);
{
UBYTE SomeBuffer[30];
memset(SomeBuffer,0,21);
PhonePasswordUsed = FALSE;
if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_ENTER_PASSWORD_TXT),SomeBuffer))
{
SomeBuffer[20] = 0;
PhonebookChanged = TRUE;
if(SomeBuffer[0])
{
UBYTE OtherBuffer[30];
memset(OtherBuffer,0,21);
if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_REPEAT_PASSWORD_TXT),OtherBuffer))
{
OtherBuffer[20] = 0;
if(!memcmp(OtherBuffer,SomeBuffer,20))
{
Encrypt(OtherBuffer,20,PhonePassword,OtherBuffer,strlen(OtherBuffer));
PhonePasswordUsed = TRUE;
}
else
MyEasyRequest(PhoneWindow,LocaleString(MSG_PHONEPANEL_ERROR_ENTERING_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
}
else
MyEasyRequest(PhoneWindow,LocaleString(MSG_PHONEPANEL_ERROR_ENTERING_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
}
}
}
LT_ShowWindow(Handle,TRUE);
LT_UnlockWindow(PhoneWindow);
break;
case GAD_EDIT:
if(Selected != ~0)
{
LT_LockWindow(PhoneWindow);
switch(MsgCode)
{
case EDIT_RATES:
if(Phonebook[Selected] == ChosenEntry)
MyEasyRequest(PhoneWindow,LocaleString(MSG_PHONEPANEL_PHONE_ENTRY_IN_USE_EDIT_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
else
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
PhonebookChanged |= RatePanel(PhoneWindow,PhoneList,Phonebook[Selected],NULL);
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
}
break;
case EDIT_PASSWORD:
PhonebookChanged |= PasswordUserPanel(Phonebook[Selected]);
break;
default:
PhonebookChanged |= EditConfig(Phonebook[Selected] -> Config,MsgCode,MsgQualifier,PhoneWindow);
break;
}
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, ~0,
TAG_DONE);
UpdateEditList(Phonebook[Selected] -> Config);
LT_SetAttributes(Handle,GAD_EDIT,
GTLV_Labels, EditList,
TAG_DONE);
LT_UnlockWindow(PhoneWindow);
LT_ShowWindow(Handle,TRUE);
}
break;
case GAD_DIALLIST:
if(!Count && Selected != ~0)
{
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
SPrintf(Phonebook[Selected] -> Node -> LocalName," %s",Phonebook[Selected] -> Header -> Name);
Phonebook[Selected] -> Count = Count++;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, PhoneList,
TAG_DONE);
}
/* If the modem is still online, provide help. */
if(Count > 0 && AskDial(PhoneWindow))
{
DialTheList = TRUE;
Done = TRUE;
}
break;
}
}
if(MsgClass == IDCMP_IDCMPUPDATE && MsgGadgetID == GAD_NAMELIST)
{
if(!(MsgQualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)) && !Online && Phonebook[MsgCode] -> Header -> Number[0])
{
Selected = MsgCode;
LT_SetAttributes(Handle,GAD_NAMELIST,
GTLV_Labels, ~0,
TAG_DONE);
Count = 1;
for(i = 0 ; i < NumPhoneEntries ; i++)
{
if(i != Selected)
{
SPrintf(Phonebook[i] -> Node -> LocalName," %s",Phonebook[i] -> Header -> Name);
Phonebook[i] -> Count = -1;
}
else
{
SPrintf(Phonebook[i] -> Node -> LocalName," 1 - %s",Phonebook[i] -> Header -> Name);
Phonebook[i] -> Count = 0;
}
}
DialTheList = TRUE;
Done = TRUE;
LT_PressButton(Handle,GAD_DIALLIST);
}
}
}
}
while(!Done);
PopWindow();
}
LT_DeleteHandle(Handle);
}
if(PhonebookChanged)
RebuildMenu = TRUE;
FreeDialList(TRUE);
if(PhoneList)
{
if(Count > 0)
{
TempNode = (struct PhoneNode *)PhoneList -> lh_Head;
while(TempNode -> VanillaNode . ln_Succ)
{
if(TempNode -> Entry -> Count != -1 && TempNode -> Entry -> Header -> Number[0])
SortToList(TempNode);
TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ;
}
if(!DialList)
DialTheList = FALSE;
}
DeletePhoneList(PhoneList);
}
return(DialTheList);
}